package order.infrastructure.repository;

import order.domain.model.Order;
import order.domain.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public class OrderRepositoryImpl implements OrderRepository {

    @Autowired
    private JpaOrderRepository jpaOrderRepository;

    @Override
    public void save(Order order) {
        jpaOrderRepository.save(order);
    }

    @Override
    public List<Order> findAll() {return jpaOrderRepository.findAll();}

    @Override
    public Order findById(Long id) {
        return jpaOrderRepository.findById(id).orElse(null);
    }

    @Override
    public List<Order> findByCustomerId(Long customerId) {
        return jpaOrderRepository.findByCustomerId(customerId);
    }

    @Override
    public void delete(Long id) {
        jpaOrderRepository.deleteById(id);
    }
}